//
//  UIBarButtonItem+BTExtension.m
//  PFBrainTwister
//
//  Created by perfayMini on 2018/5/8.
//  Copyright © 2018年 perfayMini. All rights reserved.
//

#import "UIBarButtonItem+BTExtension.h"

@implementation UIBarButtonItem (BTExtension)

+(instancetype)itemWithImage:(UIImage *)image selectImage:(UIImage *)selectImage addTarget:(id)target action:(SEL)action{
    
    UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setBackgroundImage:image forState:UIControlStateNormal];
    [button setBackgroundImage:selectImage forState:UIControlStateHighlighted];
    [button setBackgroundImage:selectImage forState:UIControlStateSelected];
    [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    button.frame = CGRectMakeWithSize(button.currentBackgroundImage.size);
    UIBarButtonItem * item = [[UIBarButtonItem alloc] initWithCustomView:button];
    return item;
}
@end
